package com.eduService.teacher.controller.home;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eduService.teacher.entity.EduCourse;
import com.eduService.teacher.service.IEduChapterService;
import com.eduService.teacher.service.IEduCourseService;
import com.eduService.teacher.utils.R;
import com.eduService.teacher.vo.chapter.chapterAndVideo;
import com.eduService.teacher.vo.course.homeCourseConditionVo;
import com.eduService.teacher.vo.course.homeCourseInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/homeCourse")
public class homeCourseController {

    @Autowired
    private IEduCourseService iEduCourseService;

    @Autowired
    private IEduChapterService iEduChapterService;


    /**
     * （前台）根据条件分页查询课程
     */
    @PostMapping("/conditionPageCourse/{page}/{limit}")
    public R conditionPageCourse(@PathVariable("page") Long page, @PathVariable("limit") Long limit,
                                 @RequestBody(required = false) homeCourseConditionVo homeCourseConditionVo) {
        Page<EduCourse> mypage = new Page<>(page, limit);
        iEduCourseService.pageQueryCourseHome(mypage, homeCourseConditionVo);
        List<EduCourse> records = mypage.getRecords();
        long total = mypage.getTotal();
        return R.ok().data("total", total).data("courses", records);
    }

    /**
     * 获取课程内容详情Info
     */
    @GetMapping("/homeGetCourseInfo/{id}")
    public R homeGetCourseInfo(@PathVariable("id") String courseid) {
        homeCourseInfo courseInfoMes = iEduCourseService.getCourseInfoMes(courseid);
        List<chapterAndVideo> chapterAndVideo = iEduChapterService.getChapterAndVideo(courseid);
        return R.ok().data("courseInfoMes", courseInfoMes).data("chapterAndVideo", chapterAndVideo);
    }

}
